﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

public partial class ajax_article_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string pagenum = Request["pagenum"].ToString();
        mynews.Text = GetNews(pagenum);
    }

    private string GetNews(string pagenum)
    {
        string myname = "";
        //设定状态
        if ((this.Session["ecrm_email"] == null) || (this.Session["ecrm_email"].ToString() == ""))
        {
        }
        else
        {
            string sid = this.Session["ecrm_uid"].ToString();
            TUser oUser = new TUser(sid);
            oUser.Select();
            myname = oUser.BigName;
        }
        
        
        string result = "<table border=0 align=left><tr><td><table width=520 id=\"mynews\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style='BORDER-COLLAPSE: collapse;font-size: 11pt;' bordercolor=\"#cfdfff\" align=\"left\">";

        /*
        result += "<thead>";
        result += "<tr height=30>";
        result += "<td align=center style=\"background-color: #ffcc99;\" nowrap=\"nowrap\">序号</td><td style=\"background-color: #ffcc99;\">姓名</td><td style=\"background-color: #ffcc99;\">公司</td><td style=\"background-color: #ffcc99;\">部门</td><td style=\"background-color: #ffcc99;\">职位</td><td style=\"background-color: #ffcc99;\">单位类型</td><td style=\"background-color: #ffcc99;\" nowrap=\"nowrap\">服务的公司</td><td style=\"background-color: #ffcc99;\">固话</td><td style=\"background-color: #ffcc99;\">手机</td><td style=\"background-color: #ffcc99;\">电邮</td>";
        result += "</tr>";
        result += "</thead>";
        */

        result += "<tbody>";
        TCMSArticle oNews = new TCMSArticle();
        oNews.GetPage(Convert.ToInt32(pagenum));
        while (oNews.RResults.Read())
        {
            DateTime issue_time=(DateTime)oNews.RResults.GetValue(oNews.RResults.GetOrdinal("issue_time"));
            
            result += "<tr height=22>";

            int status = Convert.ToInt16(oNews.RResults.GetValue(oNews.RResults.GetOrdinal("status")));
            if (status == 0)
            {
                result += "<td nowrap=\"nowrap\">·<a href=\"./my_pubnews_view.aspx?aid=" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("articleid")).ToString() + "\" target=_blank>" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("title")).ToString() + "</a>(" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("pv")).ToString() + ")";
            }
            else
            {
                result += "<td nowrap=\"nowrap\">·<span style=\"color: silver; text-decoration: line-through\">" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("title")).ToString() + "(" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("pv")).ToString() + ")</span>";
            }

            TimeSpan ts = DateTime.Today - issue_time;
            if(ts.TotalDays<7)
            {
                result += "<img src=\"./images/new01.gif\" border=0></td>";
            }
            else
            {
                result += "</td>";
            }
            
            result += "<td width=50 align=center nowrap=\"nowrap\">" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("author")).ToString() + "</td>";
            result += "<td width=100 align=center nowrap=\"nowrap\">" + issue_time.ToString("yy-MM-dd HH:mm") + "</td>";
            if (oNews.RResults.GetValue(oNews.RResults.GetOrdinal("author")).ToString()==myname)
            {
                //result += "<td><span onclick=\"delnews('" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("articleid")).ToString() + "')\" style=\"cursor:hand;\"><font color=red style=\"font-size:8pt;\">[删]</font></span></td>";
                result += "<td><span onclick=\"delnews('" + oNews.RResults.GetValue(oNews.RResults.GetOrdinal("articleid")).ToString() + "')\" style=\"cursor:hand;\"><img src=\"./images/del.gif\" border=0></span></td>";
            }
            else
            {
                result += "<td>&nbsp;</td>";
            }
            
            result += "</tr>";
        }
        result += "</tbody>";

        result += "</table></td></tr><tr><td>";

        result += oNews.GenPagebar(Convert.ToInt32(pagenum)) + "</td></tr></table>";

        return result;
    }
}
